package guoanmaker.operator.business.controller;

import guoanmaker.operator.business.model.OperatorSpaceAppointment;
import guoanmaker.operator.business.service.OperatorSpaceAppointmentServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 *  
 *
 * @author huZhaoyu 
 * @ClassName: OperatorSpaceAppointmentController
 * @Description: OperatorSpaceAppointmentController 
 * @date 2017/6/28 下午3:01 
 */
@RestController
@RequestMapping(ApiController.OPERATOR_SPACE_APPOINTMENT_URL)
public class OperatorSpaceAppointmentController {
    private final AjaxJson ajaxJson;
    private final OperatorSpaceAppointmentServiceInterface operatorSpaceAppointmentServiceInterface;

    public OperatorSpaceAppointmentController(AjaxJson ajaxJson, OperatorSpaceAppointmentServiceInterface operatorSpaceAppointmentServiceInterface) {
        this.ajaxJson = ajaxJson;
        this.operatorSpaceAppointmentServiceInterface = operatorSpaceAppointmentServiceInterface;
    }

    /** 
    * @Title: saveSpaceAppointment
    * @Description: 新增/修改空间预约 
    * @param: OperatorSpaceAppointment   
    * @return AjaxJson    
    * @throws 
    */
    @ApiOperation(value = "保存空间预约", notes = "新增/修改空间预约")
    @PostMapping(value = "saveSpaceAppointment")
    public AjaxJson saveSpaceAppointment(@RequestBody OperatorSpaceAppointment operatorSpaceAppointment) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceAppointmentServiceInterface.saveSpaceAppointment(operatorSpaceAppointment));
    }

    /** 
     * @Title: deleteSpaceAppointmentById
     * @Description: 根据Id删除空间预约
     * @param: String id  
     * @return AjaxJson 
     * @throws 
     */
    @ApiOperation(value = "删除空间预约", notes = "根据Id删除空间预约")
    @DeleteMapping(value = "delete/{id}")
    public AjaxJson deleteSpaceAppointmentById(@PathVariable(value = "id") String id) {
        operatorSpaceAppointmentServiceInterface.deleteSpaceAppointmentById(id);
        return ajaxJson.setSuccess(true).setStatus(200).setData("数据删除成功!");
    }

    /**
     * @return OperatorSpaceAppointment    
     * @Title: getSpaceAppointmentById 
     * @Description: 根据Id查询空间预约
     * @param: String id   
     * @throws 
     */
    @ApiOperation(value = "根据Id查询空间预约", notes = "根据Id查询空间预约")
    @GetMapping(value = "getSpaceAppointmentById")
    public AjaxJson getSpaceAppointmentById(@RequestParam(value = "id") String id) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceAppointmentServiceInterface.getSpaceAppointmentById(id));
    }

    /**
     * @return AjaxJson   
     * @Title: getAllSpaceAppointment
     * @Description: 查找所有空间预约 
     * @throws 
     */
    @ApiOperation(value = "查找所有空间预约", notes = "查找所有空间预约")
    @GetMapping(value = "getAllSpaceAppointment")
    public AjaxJson getAllSpaceAppointment() {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceAppointmentServiceInterface.getAllSpaceAppointment());
    }

    /**
     * @return AjaxJson   
     * @Title: getAllSpaceAppointmentByPage 
     * @Description: 查询所有空间预约并分页
     * @param: Integer page 页码
     * @param: Integer size 条数
     * @throws 
     */
    @ApiOperation(value = "分页查询空间预约", notes = "分页查询空间预约")
    @GetMapping(value = "getAllSpaceAppointmentByPage")
    public AjaxJson getAllSpaceAppointmentByPage(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                           @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceAppointmentServiceInterface.getAllSpaceAppointmentByPage(page, size));
    }

    /**
     * @return AjaxJson   
     * @Title: findBySpaceTitleContainingOrderByCreateDateDesc 
     * @Description: 根据姓名手机分页查询所有空间预约
     * @param: String appointmentName 用户姓名
     * @param: String appointmentPhone 用户手机
     * @throws 
     */
    @ApiOperation(value = "根据姓名手机分页查询所有空间预约", notes = "根据姓名手机分页查询所有空间预约")
    @GetMapping(value = "findByAppointmentNameAndAppointmentPhone")
    public AjaxJson findByAppointmentNameAndAppointmentPhone(@RequestParam(value = "appointmentName") String appointmentName,
                                                             @RequestParam(value = "appointmentPhone") String appointmentPhone,
                                                             @RequestParam(value = "page", defaultValue = "0") Integer page,
                                                             @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSpaceAppointmentServiceInterface.findByAppointmentNameContainingAndAppointmentPhoneContainingOrderByCreateDateDesc(appointmentName, appointmentPhone, page, size));
    }

}
